
package com.aitongyi.rabbitmq.helloworld;


import com.aitongyi.rabbitmq.Base;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 生产者
 * @author kata
 *
 */
public class ProducerJ extends Base{

  private final static String QUEUE_NAME = "hello1";

  public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(Base.hostname);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, false, false, true, null);
    StringBuffer message = new StringBuffer("what fuck!");
    Map<String,String> param = new HashMap<>();
    param.put("key","abcd");
    param.put("value","121");
    channel.basicPublish("", QUEUE_NAME, null, message.toString().getBytes("UTF-8"));
//    System.out.println("P [x] Sent '" + message + "'");
    channel.close();
    connection.close();
  }
}
